Draw how an enemy or a character acts as boxes and arrows - patrol, see the player, chase, attack - start from a ready-made one, and call it from the object's Step event.
A behavior says what a character does, and when it changes what it is doing. A guard might patrol, then chase you when it sees you, then attack when it touches you, then go back when you get away.
You draw that. Each thing the guard can be doing is a state, shown as a box. An arrow from one box to another says when it changes. Gbabel writes a script that does it, and you can still read the script.
The designer lives in the Code tab, in a section called Behaviors, under HUD & Menus.
guard.Click a name in the list to open it again. Right-click it to rename, duplicate, show the script or delete it.
A behavior is used by being called from an object's Step event:
guard();Each object that does this has its own place in the states. Ten guards can share one behavior, and each one is patrolling, chasing or attacking on its own.
To get an object ready, pick it in Used by under Use in an object. Gbabel then does two things for you:
guard_state, guard_timer, guard_leg, where it started, what it was told, and one for each variable of the behavior). You will see them between two comment lines that start with >>> behavior and <<< behavior. Leave them there. When you add a variable to the behavior, the objects that use it get the new line by themselves.guard(); to the object's Step event, if it is not there yet.To stop an object using the behavior, press Remove beside it in Used by. Gbabel takes out the lines it added to the Create event and the guard(); line of the Step event, and leaves everything else you wrote there. You can undo it.
You can also type guard(); in a Step event yourself. Then Things to fix tells you the object still needs its numbers, and Set up does it.
It works like the other pictures in Gbabel.
+ Group makes a bigger box that holds states that belong together, like Combat with Approach, Attack and Recover inside it. Drop a state into the box and it becomes part of the group; drag it out and it is out again. Moving the group by its title moves the states with it.
Any state shows a special box. An arrow drawn from it is taken from every state, like "hp is at or below 0, then go to dead". Each such arrow says whether it is looked at before the state's own arrows or after them. It never fires in the state it points at. To keep a state out of reach of every such arrow (a defeated enemy that a late hit must not bring back to life), tick Ignore arrows from any state in that state's Properties; its own arrows still work.
A state has three lists of actions.
| List | When it happens |
|---|---|
| When it enters | Once, when it moves into this state. |
| Every frame it is here | Every frame while it is in this state. |
| When it leaves | Once, when it moves out of this state. |
A state can also name an animation. It plays when the state is entered (with Start over if you want it from the first picture again), before the state's own When it enters actions. The animation is picked from the animations of the objects that use the behavior.
For a game seen from above, open Pictures by direction in the state's details (it starts closed). The Animation above is the picture for facing down. Up and Sideways are the pictures for those two ways, and a way left empty plays the Animation above, so a state that has none of them works as before.
_down, _up and _side (a plain name counts as down): with Animation set to walk_down, it finds walk_up and walk_side.Each action is a card. Pick one from Add an action; the box groups them by what they do (Moving, Looks, Sound, Objects, Variables, Choices, The world), and each list only offers the actions that make sense there. Where your project has the things, you pick from a list: objects, paths, sounds, sprites, particle effects, sprite effects, animations and scripts.
| Action | What it does |
|---|---|
| Stand still | Stops moving. |
| Move toward / away from something | Walks toward (or away from) the nearest one of an object, and slides along walls. |
| Move in a direction | Walks one of 8 directions, or an angle, every frame. |
| Keep a distance from something | Closer when it is too far, back off when it is too near. |
| Circle around something | Walks round the nearest one of an object at about the same distance. |
| Dash toward something | A short fast burst when the state starts, then it stops. |
| Jump | For a side-view game: jumps only when there is solid ground under its feet. It needs gravity to come back down. |
| Bounce off walls | Walks one way and turns back at something solid, and at ledges if you tick it. A game where every Player movement is top-down has no ground to end, so the ledge turning is left out there. |
| Go back to where it started | Walks home and stops there. |
| Jump to a spot or to something | Appears at once at a spot, or on the nearest one of an object. |
| Follow a path | Walks along a path from the Paths tab. In Every frame it starts once, when the state starts, and keeps going. It stops following when the state is left. |
| Stop following the path | Stops where it is. |
| Walk between two points | Walks back and forth between two spots in the room. |
| Wander | Walks in a random direction and picks a new one every so often. |
| Face something | Turns its direction toward the nearest one of an object, so a shot made here goes that way. |
| Face left or right toward something | Mirrors the picture so it looks at the nearest one of an object. |
| Change the picture | Shows a different sprite. |
| Play an animation | Plays one of the object's animations, picked from a list. |
| Blink | Flashes on and off for a number of frames after the state starts. |
| Hide or show itself | Makes the picture disappear, or come back. |
| Play a sprite effect / Stop the sprite effect | Starts (or ends) an effect from the Overlay Effects tab on this object only, like a hit flash. |
| Play a sound | Plays a sound once. |
| Shake the screen | Shakes the camera for a moment. |
| Burst of particles | Sets off a particle effect at its own spot. |
| Make an object | Makes a new object, like a shot. In Every frame it makes one every so many frames, and it can aim it at something. |
| Destroy itself | Removes this object from the room. |
| Set an alarm | Starts one of the 12 alarms counting down. |
| Change a variable of another object | The one it touches, or the nearest one of an object: take 1 from the player's hp. |
| Tell another object something | Sends a word to the nearest one of an object, or to all of them. |
| Change a variable | Sets a variable, or adds to it or takes from it, or sets it to a random number. The variable can be the object's, the whole game's, or this behavior's own. |
| Run a script | Runs one of your own scripts and hands it numbers. |
| Run a line of code | One line of GBML for anything not on this list. The compiler checks it and Things to fix shows what it says. |
| Wait a bit, then do the rest | The actions under it only start after the state has lasted that long. |
| If ... then ... otherwise | Does some cards when something is true and others when it is not. It uses the same conditions as an arrow and can hold other Ifs. |
| Repeat | Does the cards inside this many times in a row. |
| Pick one at random | Picks ONE of its choices by chance. A choice with a bigger weight is picked more often. |
+ Variable gives the behavior something to remember for each object that uses it: a number, a yes or no, or a stopwatch that counts the frames by itself. Actions and conditions can set it, add to it and compare it. A state can count how often it comes in by adding 1 to one of your number variables each time.
An arrow has conditions. It is taken when all of them hold, or when any one of them holds, as you choose (the choice appears when there are two or more). Every condition has a not button that turns it round, and a group condition holds other conditions. An arrow with no conditions is taken at once.
| Condition | It holds when |
|---|---|
| Something is close or far | The nearest one of an object is within, or farther than, a number of pixels. |
| It can see something | The nearest one of an object is within a number of pixels and nothing solid is in the way. You can name an object, like a wall, that also blocks the view. |
| It has been here a while | The state has lasted this many frames. |
| A variable compares with a number | Like hp is at or below 3. |
| A button | A button was pressed, or is held down. |
| It is touching something | It overlaps the nearest one of an object. |
| Its path has ended | It was following a path that stops at the end, and it got there. |
| A random chance each frame | Happens by luck. 2 means about once every 50 frames. |
| Its animation has finished | A play-once animation reached its last picture (you can name which). |
| Its animation is on a picture | The animation is on, or past, a picture. |
| An animation event happened | A picture with this event name (from the Animations window) was just shown. |
| Its attack hits something | The attack boxes of its animation touch the body boxes of an object. |
| It is standing on something | For a side-view game: there is solid ground under its feet. |
| It is off the screen | It is outside what the camera shows. |
| How many of an object exist | Compares the number of an object in the room with a number. |
| A variable of another object compares | Looks at a variable of the nearest one of an object. |
| It was told something | Another object sent it this word. It counts for one frame only. |
Every frame the arrows out of the state are looked at in order, and the first one whose conditions hold is taken. So the order is the priority. The list in Properties shows the order. ▲ and ▼ move an arrow. Arrows from Any state come before the state's own arrows or after them, as each one says.
Give several arrows out of one state a chance weight (anything above 0) and, of those that hold at the same moment, one is picked by chance, in proportion to the weights: 3 is picked three times as often as 1.
When an arrow is taken, the old state's When it leaves actions run once, the new state starts counting from 0, and its When it enters actions run once. The new state's Every frame actions begin on the next frame, so one frame never passes through two states.
path_guard. Every frame: nothing.obj_player at 1.2.obj_shot every 30 frames, aimed at obj_player.Arrows, in this order:
obj_player within 64 pixels.obj_player.obj_player is farther than 100 pixels and it has been here 30 frames.obj_player is farther than 20 pixels.Pick obj_guard in Use in an object and play.
This is the Boss with two phases ready-made behavior, drawn with groups and an arrow from any state.
hp is at or below 10, from whichever state of Phase 1 it is in.hp is at or below 0, before any other arrow. defeated shakes the screen, waits 90 frames and destroys the boss.To follow the boss while it plays, open it in the Inspector of the Play tab: the variable boss_state shows the name of the state, and that box lights up in the designer.
A boss's attacks are about timing: how long the warning shows, when the strike lands, how long the boss can be hurt afterward. You could tune that with timers and Wait cards, but a pattern puts it on a timeline you can read.
Pick a state and open Attack pattern in its details. It is a strip of steps, each one a section you can open for its settings:
Times are in frames: 60 frames are one second. Under the steps, a bar shows the timing, and Play this pattern runs a cursor over it so you can see the rhythm without building the game.
Where it happens. A step that aims asks Aim at: the player (the nearest one of the object you pick, or The player: any object that uses a Player movement), NEAR the player (a random spot within so many pixels, and never right on them), a fixed spot, a random spot in the room, or the spot the last step aimed at, so the strike lands exactly where the warning was shown.
Fair play. When you add an Attack, Gbabel adds an Open a hit window step after it, so the player is rewarded for dodging. While the window is open the behavior's yes-or-no variable hit_window is yes (the boss's own variable is <behavior>_hit_window); check it where your boss takes damage. Things to fix tells you when an attack has no window after it.
Phases. Open Phases in the details to group states by health. Pick the variable that is the boss's health and its full value, then + Add a phase: it starts when the health is at or below a percent, its states run its patterns faster (1.3 is a third faster) and every Repeat can repeat more times. A state joins a phase with Phase in its details. When the health drops, a state of an earlier phase goes to the first state of the phase. To make a phase's version of an attack, duplicate the state and give the copy the phase.
Hurt bosses flicker. Under Attack pattern, pick the boss's health variable and a Harmless for time (about 2 seconds to begin with; 0 turns it off). When the health drops, the boss flickers: its attacks and its Change a variable of another object cards hurt nobody, no hit window opens, and the variable <behavior>_harmless counts the frames left. Check it where your boss takes damage: above 0 means do not hurt it.
Hit box. An Attack that makes or shoots an object has a Hit box: 75 percent of the object's picture to begin with, so a near miss is a miss. 100 leaves the box as the object has it.
A design that has no patterns writes the same script it always did. A pattern is ordinary behavior code, so it works on every console that does the behaviors.
The script is read-only in the code editor, because it is written again every time you change the design. At the top of its window you see Made by the behavior designer and two buttons: Open in designer, and Make it my own script. The second one copies the script into a new, ordinary script that you can edit. The copy is no longer connected to the designer, and it keeps using the same numbers.